package com.yoo.ons.dialog

import android.app.Activity
import android.graphics.Color
import android.text.Spannable
import android.text.SpannableStringBuilder
import android.text.style.ForegroundColorSpan
import android.widget.TextView
import com.yoo.module_base.utils.SaveDeviceUtil
import com.yoo.module_base.utils.SendEmailUtils
import com.yoo.module_base.utils.setOnClickCallback
import com.yoo.ons.BuildConfig
import com.yoo.ons.R
import razerdp.basepopup.BasePopupWindow

class HelpCenterPopup(var activity: Activity) :  BasePopupWindow(activity) {
    init {
        setContentView(R.layout.popup_help_center)
        initView()
    }

    private fun initView() {
        val dialogContent = findViewById<TextView>(R.id.popup_content)
        val spannableStringBuilder = SpannableStringBuilder(activity.getString(com.yoo.module_res.R.string.help_center_tip))
        spannableStringBuilder.setSpan(ForegroundColorSpan(Color.parseColor("#FF3EAB")), 11, 32, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
        dialogContent.text = spannableStringBuilder
        val dialogCancel = findViewById<TextView>(R.id.popup_cancel)
        dialogCancel.setOnClickCallback {
            dismiss()
        }
        val dialogConfirm = findViewById<TextView>(R.id.popup_copy_email)
        dialogConfirm.setOnClickCallback {
            val emailTitle = String.format(activity.getString(com.yoo.module_res.R.string.send_email_default_title),
               SaveDeviceUtil.getUserCode(), BuildConfig.VERSION_NAME)
            SendEmailUtils.sendEmail(activity,emailTitle,activity.getString(com.yoo.module_res.R.string.send_email_default_txt))
            dismiss()
        }
        setOutSideDismiss(true)
    }
}